package com.muyu.cloud.system.factory;

import com.muyu.cloud.system.domain.UserInfo;
import com.muyu.cloud.system.remote.RemoteUserInfoService;
import com.muyu.common.constant.ServerNameConstants;
import com.muyu.common.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.cloud.openfeign.FallbackFactory;

/**
 * @Author: DongZeLiang
 * @date: 2024/5/24
 * @Description: 用户远程调用熔断机制
 * @Version: 1.0
 */
@Log4j2
public class UserInfoRemoteFactory implements FallbackFactory<RemoteUserInfoService> {
    @Override
    public RemoteUserInfoService create (Throwable cause) {
        return new RemoteUserInfoService() {

            /**
             * 通过用户名称查询用户信息
             *
             * @param userName 用户名称
             *
             * @return 用户信息
             */
            @Override
            public Result<UserInfo> findByUserName (String userName) {
                log.error("服务[{}]调用接口发生异常：[{}]", ServerNameConstants.SYSTEM_NAME, cause.getMessage(), cause);
                return Result.error(cause.getMessage());
            }
        };
    }
}
